<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>面试题之JS | Han's Blog</title><meta name="keywords" content="JS"><meta name="author" content="憨憨一个"><meta name="copyright" content="憨憨一个"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="js数据类型7 大数据类型  Number (数字) String (字符串) Boolean (布尔) Symbol (符号) Object (对象) function (函数) Array (数组) Date (日期) RegExp (正则表达式)   Null (空) Undefined (未定义)  五种基本数据类型 Number,Null,Undefined,Boolean,String">
<meta property="og:type" content="article">
<meta property="og:title" content="面试题之JS">
<meta property="og:url" content="http://blog.better2020.top/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/index.html">
<meta property="og:site_name" content="Han&#39;s Blog">
<meta property="og:description" content="js数据类型7 大数据类型  Number (数字) String (字符串) Boolean (布尔) Symbol (符号) Object (对象) function (函数) Array (数组) Date (日期) RegExp (正则表达式)   Null (空) Undefined (未定义)  五种基本数据类型 Number,Null,Undefined,Boolean,String">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://blog.better2020.top/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/top_img.png">
<meta property="article:published_time" content="2021-08-27T06:19:17.000Z">
<meta property="article:modified_time" content="2022-03-17T05:25:22.810Z">
<meta property="article:author" content="憨憨一个">
<meta property="article:tag" content="JS">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://blog.better2020.top/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/top_img.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://blog.better2020.top/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="preconnect" href="//zz.bdstatic.com"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><script>var GLOBAL_CONFIG = { 
  root: '/',
  hexoversion: '5.2.0',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isSidebar: true,
  postUpdate: '2022-03-17 13:25:22'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {
  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }

  const autoChangeMode = 'false'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }
})()</script><meta name="generator" content="Hexo 5.2.0"><link rel="alternate" href="/atom.xml" title="Han's Blog" type="application/atom+xml">
</head><body><div id="mobile-sidebar"><div id="menu_mask"></div><div id="mobile-sidebar-menus"><div class="mobile_author_icon"><img class="avatar-img" src="/null" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="mobile_post_data"><div class="mobile_data_item is-center"><div class="mobile_data_link"><a href="/archives/"><div class="headline">文章</div><div class="length_num">25</div></a></div></div><div class="mobile_data_item is-center">      <div class="mobile_data_link"><a href="/tags/"><div class="headline">标签</div><div class="length_num">16</div></a></div></div><div class="mobile_data_item is-center">     <div class="mobile_data_link"><a href="/categories/"><div class="headline">分类</div><div class="length_num">2</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div></div></div></div><div id="body-wrap"><div id="sidebar"><i class="fas fa-arrow-right on" id="toggle-sidebar"></i><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar">     </div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#js%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.</span> <span class="toc-text">js数据类型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#null%E4%B8%8Eundefined"><span class="toc-number">2.</span> <span class="toc-text">null与undefined</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%A4%E6%96%AD%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%96%B9%E6%B3%95"><span class="toc-number">3.</span> <span class="toc-text">判断数据类型的方法</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E3%80%81typeof"><span class="toc-number">3.1.</span> <span class="toc-text">一、typeof</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E3%80%81instanceof"><span class="toc-number">3.2.</span> <span class="toc-text">二、instanceof</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%89%E3%80%81Object-prototype-toString-call"><span class="toc-number">3.3.</span> <span class="toc-text">三、Object.prototype.toString.call()</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8E%9F%E7%94%9Fajax"><span class="toc-number">4.</span> <span class="toc-text">原生ajax</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AF%B9%E8%B1%A1%E6%B7%B1%E6%B5%85%E6%8B%B7%E8%B4%9D"><span class="toc-number">5.</span> <span class="toc-text">对象深浅拷贝</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%85%E6%8B%B7%E8%B4%9D"><span class="toc-number">5.1.</span> <span class="toc-text">浅拷贝</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%B1%E6%8B%B7%E8%B4%9D"><span class="toc-number">5.2.</span> <span class="toc-text">深拷贝</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#this%E6%8C%87%E5%90%91%E9%97%AE%E9%A2%98"><span class="toc-number">6.</span> <span class="toc-text">this指向问题</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E5%8E%BB%E9%87%8D%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E5%BC%8F"><span class="toc-number">7.</span> <span class="toc-text">数组去重的几种方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%B1%BB%E6%95%B0%E7%BB%84%E8%BD%AC%E5%8C%96%E4%B8%BA%E6%95%B0%E7%BB%84"><span class="toc-number">8.</span> <span class="toc-text">类数组转化为数组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%98%B2%E6%8A%96%E8%8A%82%E6%B5%81"><span class="toc-number">9.</span> <span class="toc-text">防抖节流</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%97%AD%E5%8C%85"><span class="toc-number">10.</span> <span class="toc-text">闭包</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98"><span class="toc-number">11.</span> <span class="toc-text">跨域问题</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8E%9F%E5%9E%8B%E9%93%BE%E7%9B%B8%E5%85%B3"><span class="toc-number">12.</span> <span class="toc-text">原型链相关</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8B%E4%BB%B6%E5%A7%94%E6%89%98"><span class="toc-number">13.</span> <span class="toc-text">事件委托</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BE%93%E5%85%A5url%E4%B9%8B%E5%90%8E%EF%BC%8C%E5%88%B0%E5%BA%95%E5%8F%91%E7%94%9F%E4%BA%86%E4%BB%80%E4%B9%88%EF%BC%9F"><span class="toc-number">14.</span> <span class="toc-text">输入url之后，到底发生了什么？</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#http%E4%B8%8Ehttps"><span class="toc-number">15.</span> <span class="toc-text">http与https</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%87%8D%E6%8E%92%E4%B8%8E%E9%87%8D%E7%BB%98"><span class="toc-number">16.</span> <span class="toc-text">重排与重绘</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#ES6%E6%96%B0%E7%89%B9%E6%80%A7"><span class="toc-number">17.</span> <span class="toc-text">ES6新特性</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#const%E5%92%8Clet"><span class="toc-number">17.1.</span> <span class="toc-text">const和let</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E7%9A%84%E8%A7%A3%E6%9E%84%E8%B5%8B%E5%80%BC"><span class="toc-number">17.2.</span> <span class="toc-text">变量的解构赋值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A8%A1%E6%9D%BF%E5%AD%97%E9%9D%A2%E9%87%8F"><span class="toc-number">17.3.</span> <span class="toc-text">模板字面量</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B1%95%E5%BC%80%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">17.4.</span> <span class="toc-text">展开运算符</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%89%A9%E4%BD%99%E5%8F%82%E6%95%B0-%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0"><span class="toc-number">17.5.</span> <span class="toc-text">剩余参数(可变参数)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#ES6%E7%AE%AD%E5%A4%B4%E5%87%BD%E6%95%B0"><span class="toc-number">17.6.</span> <span class="toc-text">ES6箭头函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%BB%98%E8%AE%A4%E5%8F%82%E6%95%B0%E5%87%BD%E6%95%B0"><span class="toc-number">17.7.</span> <span class="toc-text">默认参数函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%BB%98%E8%AE%A4%E5%80%BC%E4%B8%8E%E8%A7%A3%E6%9E%84"><span class="toc-number">17.8.</span> <span class="toc-text">默认值与解构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Promise"><span class="toc-number">17.9.</span> <span class="toc-text">Promise</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#for%E2%80%A6of%E5%BE%AA%E7%8E%AF"><span class="toc-number">17.10.</span> <span class="toc-text">for…of循环</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%B1%BB%E4%B8%8E%E7%BB%A7%E6%89%BF"><span class="toc-number">17.11.</span> <span class="toc-text">类与继承</span></a></li></ol></li></ol></div></div></div><header class="post-bg" id="page-header" style="background-image: url(/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/top_img.png)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Han's Blog</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><div id="post-title"><div class="posttitle">面试题之JS</div></div><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-08-27T06:19:17.000Z" title="发表于 2021-08-27 14:19:17">2021-08-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-03-17T05:25:22.810Z" title="更新于 2022-03-17 13:25:22">2022-03-17</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/code/">code</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout_post" id="content-inner"><article id="post"><div class="post-content" id="article-container"><h2 id="js数据类型"><a href="#js数据类型" class="headerlink" title="js数据类型"></a>js数据类型</h2><p>7 大数据类型</p>
<ul>
<li>Number (数字)</li>
<li>String (字符串)</li>
<li>Boolean (布尔)</li>
<li>Symbol (符号)</li>
<li>Object (对象)<ul>
<li>function (函数)</li>
<li>Array (数组)</li>
<li>Date (日期)</li>
<li>RegExp (正则表达式)</li>
</ul>
</li>
<li>Null (空)</li>
<li>Undefined (未定义)</li>
</ul>
<p>五种基本数据类型 Number,Null,Undefined,Boolean,String<br>一种复杂数据类型 Object<br>es6 新加入 symbol</p>
<h2 id="null与undefined"><a href="#null与undefined" class="headerlink" title="null与undefined"></a>null与undefined</h2><ul>
<li>undefined 已声明，未定义</li>
<li>null 空值</li>
</ul>
<h2 id="判断数据类型的方法"><a href="#判断数据类型的方法" class="headerlink" title="判断数据类型的方法"></a>判断数据类型的方法</h2><h3 id="一、typeof"><a href="#一、typeof" class="headerlink" title="一、typeof"></a>一、typeof</h3><ul>
<li>优点：能够快速区分基本数据类型 </li>
<li>缺点：不能将Object、Array和Null区分，都返回object</li>
<li>注意！ typeof(null)//object 但typeof 可以检测function</li>
</ul>
<h3 id="二、instanceof"><a href="#二、instanceof" class="headerlink" title="二、instanceof"></a>二、instanceof</h3><p>可进一步区分object为对象还是数组还是函数</p>
<ul>
<li>优点：能够区分Array、Object和Function，适合用于判断自定义的类实例对象 </li>
<li>缺点：Number，Boolean，String基本数据类型不能判断</li>
</ul>
<h3 id="三、Object-prototype-toString-call"><a href="#三、Object-prototype-toString-call" class="headerlink" title="三、Object.prototype.toString.call()"></a>三、Object.prototype.toString.call()</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> toString = <span class="built_in">Object</span>.prototype.toString;</span><br><span class="line"> </span><br><span class="line"><span class="built_in">console</span>.log(toString.call(<span class="number">1</span>));                      <span class="comment">//[object Number]</span></span><br><span class="line"><span class="built_in">console</span>.log(toString.call(<span class="literal">true</span>));                   <span class="comment">//[object Boolean]</span></span><br><span class="line"><span class="built_in">console</span>.log(toString.call(<span class="string">&#x27;abc&#x27;</span>));                  <span class="comment">//[object String]</span></span><br><span class="line"><span class="built_in">console</span>.log(toString.call([]));                     <span class="comment">//[object Array]</span></span><br><span class="line"><span class="built_in">console</span>.log(toString.call(&#123;&#125;));                     <span class="comment">//[object Object]</span></span><br><span class="line"><span class="built_in">console</span>.log(toString.call(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;&#125;));           <span class="comment">//[object Function]</span></span><br><span class="line"><span class="built_in">console</span>.log(toString.call(<span class="literal">undefined</span>));              <span class="comment">//[object Undefined]</span></span><br><span class="line"><span class="built_in">console</span>.log(toString.call(<span class="literal">null</span>));                   <span class="comment">//[object Null]</span></span><br></pre></td></tr></table></figure>

<ul>
<li>优点：精准判断数据类型 </li>
<li>缺点：写法繁琐不容易记，推荐进行封装后使用<br><b>为什么可以这么干？</b><br>Number Boolean String这些类型原型也指向Object,可以调用它上面的toString<br><b>那为什么要用prototype再call一下呢？</b><br>因为其实Number String之类的已经重写过了toString方法</li>
</ul>
<h2 id="原生ajax"><a href="#原生ajax" class="headerlink" title="原生ajax"></a>原生ajax</h2><p>其实很简单<br>1.创建xhr(xmlhttprequest)对象<br>2.请求参数，url ，类型，参数等<br>3.发送请求<br>4.监听回调xhr.onreadystate change,说明请求完成</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//步骤一:创建异步对象</span></span><br><span class="line"><span class="keyword">var</span> ajax = <span class="keyword">new</span> XMLHttpRequest();</span><br><span class="line"><span class="comment">//步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端</span></span><br><span class="line">ajax.open(<span class="string">&#x27;get&#x27;</span>,<span class="string">&#x27;getStar.php?starName=&#x27;</span>+name);</span><br><span class="line"><span class="comment">//步骤三:发送请求</span></span><br><span class="line">ajax.send();</span><br><span class="line"><span class="comment">//步骤四:注册事件 onreadystatechange 状态改变就会调用</span></span><br><span class="line">ajax.onreadystatechange = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;   <span class="keyword">if</span> (ajax.readyState==<span class="number">4</span> &amp;&amp;ajax.status==<span class="number">200</span>) &#123;</span><br><span class="line">    <span class="comment">//步骤五 如果能够进到这个判断 说明 数据 完美的回来了,并且请求的页面是存在的　　　　console.log(ajax.responseText);//输入相应的内容  　　&#125;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="对象深浅拷贝"><a href="#对象深浅拷贝" class="headerlink" title="对象深浅拷贝"></a>对象深浅拷贝</h2><h3 id="浅拷贝"><a href="#浅拷贝" class="headerlink" title="浅拷贝"></a>浅拷贝</h3><p>一.object.assign(target,souce)//Object.assign({},{a:1,b:2})</p>
<p>二.手动实现<br>自己实现也很简单，就一个for循环进行赋值</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">simpleClone</span>(<span class="params">obj</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> result = &#123;&#125;;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">var</span> i <span class="keyword">in</span> obj) &#123;</span><br><span class="line">        result[i] = obj[i];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="深拷贝"><a href="#深拷贝" class="headerlink" title="深拷贝"></a>深拷贝</h3><p>一.json.parse(json.stringfy(obj))<br>缺点：<br>（1）如果对象里有函数,函数无法被拷贝下来<br>（2）无法拷贝Obj对象原型链上的属性和方法<br>（3）当数据的层次很深，会栈溢出<br>二.手动实现<br>也没想象中难，就用递归把所有属性都复制下来,但是其中有比较多的细节可以注意</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">deepClone</span>(<span class="params">obj</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> result = &#123;&#125;;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">var</span> i <span class="keyword">in</span> obj) &#123;</span><br><span class="line">        <span class="function"><span class="title">if</span>(<span class="params"><span class="keyword">typeof</span> obj[i] === <span class="string">&quot;object&quot;</span></span>)</span>&#123;</span><br><span class="line">             result[i] = deepClone(obj[i])</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            result[i] = obj[i];</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">deepCopyTwo</span>(<span class="params">obj</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">let</span> objClone = <span class="built_in">Array</span>.isArray(obj) ? [] : &#123;&#125;;</span><br><span class="line">    <span class="keyword">if</span> (obj &amp;&amp; <span class="keyword">typeof</span> obj == <span class="string">&#x27;object&#x27;</span>) &#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">const</span> key <span class="keyword">in</span> obj) &#123;</span><br><span class="line">            <span class="comment">//判断obj子元素是否为对象，如果是，递归复制</span></span><br><span class="line">            <span class="keyword">if</span> (obj[key] &amp;&amp; <span class="keyword">typeof</span> obj[key] === <span class="string">&quot;object&quot;</span>) &#123;</span><br><span class="line">                objClone[key] = deepCopyTwo(obj[key]);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                <span class="comment">//如果不是，简单复制</span></span><br><span class="line">                objClone[key] = obj[key];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> objClone;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="this指向问题"><a href="#this指向问题" class="headerlink" title="this指向问题"></a>this指向问题</h2><!-- - this指的是函数运行时所在的环境 -->
<ul>
<li>this指向-记住一句话：谁调用，指向谁</li>
</ul>
<p>下面来做几道题理解<br>第一道</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">foo</span>(<span class="params"></span>) </span>&#123; </span><br><span class="line">    <span class="built_in">console</span>.log(<span class="built_in">this</span>.bar); </span><br><span class="line">&#125; </span><br><span class="line"><span class="keyword">var</span> bar = <span class="string">&quot;bar1&quot;</span>; </span><br><span class="line"><span class="keyword">var</span> o2 = &#123;<span class="attr">bar</span>: <span class="string">&quot;bar2&quot;</span>, <span class="attr">foo</span>: foo&#125;; </span><br><span class="line"><span class="keyword">var</span> o3 = &#123;<span class="attr">bar</span>: <span class="string">&quot;bar3&quot;</span>, <span class="attr">foo</span>: foo&#125;; </span><br><span class="line"></span><br><span class="line">foo();   <span class="comment">//  &quot;bar1&quot;;  window.foo()       </span></span><br><span class="line">o2.foo();   <span class="comment">//&quot;bar2&quot;       </span></span><br><span class="line">foo.call(o3);  <span class="comment">//&quot;bar3&quot; 改变this指向o3</span></span><br></pre></td></tr></table></figure>
<p>第二道</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> name = <span class="string">&#x27;Nicolas&#x27;</span>;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">Person</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="built_in">this</span>.name = <span class="string">&#x27;Smiley&#x27;</span>;</span><br><span class="line">    <span class="built_in">this</span>.sayName=<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="built_in">this</span>); </span><br><span class="line">        <span class="built_in">console</span>.log(<span class="built_in">this</span>.name); <span class="comment">//&#x27;Smiley&#x27;</span></span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="built_in">this</span>.sayName, <span class="number">0</span>);     <span class="comment">// 第二次输出,&#x27;Nicolas&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> person = <span class="keyword">new</span> Person();  </span><br><span class="line">person.sayName();	<span class="comment">// &#x27;Smiley&#x27;,&#x27;Nicolas&#x27;</span></span><br><span class="line"><span class="comment">//person.sayname();指向person</span></span><br><span class="line"><span class="comment">//setTimeout 指向window</span></span><br></pre></td></tr></table></figure>
<p>第三道</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> length = <span class="number">10</span>;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">	<span class="built_in">console</span>.info(<span class="built_in">this</span>.length)</span><br><span class="line">&#125;</span><br><span class="line">fn();  <span class="comment">// A window.fn(); 10</span></span><br><span class="line"><span class="keyword">let</span> Person = &#123;</span><br><span class="line">	len: <span class="number">5</span>,</span><br><span class="line">	say: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">		fn();  <span class="comment">// B  隐式调用 默认还是window；10</span></span><br><span class="line">		<span class="built_in">arguments</span>[<span class="number">0</span>]();  <span class="comment">// C</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line">Person.say(fn);</span><br></pre></td></tr></table></figure>

<p>另外需要记住的：</p>
<ul>
<li>箭头函数指向最近作用的this</li>
<li>bind，apply,call可以改变this指向</li>
</ul>
<h2 id="数组去重的几种方式"><a href="#数组去重的几种方式" class="headerlink" title="数组去重的几种方式"></a>数组去重的几种方式</h2><ul>
<li>for循环 利用for嵌套for，然后splice去重（ES5中最常用）</li>
<li>filter</li>
<li>Set<br>…<br>总结来说就是两个类型</li>
</ul>
<p>1.两层循环法<br>2.利用语法自身键不可重复性</p>
<h2 id="类数组转化为数组"><a href="#类数组转化为数组" class="headerlink" title="类数组转化为数组"></a>类数组转化为数组</h2><p>Array.prototype.slice.call()</p>
<h2 id="防抖节流"><a href="#防抖节流" class="headerlink" title="防抖节流"></a>防抖节流</h2><p>节流，函数一段时间内只触发一次 //写个滚动分页就能用到了<br>触底加载下一页数据，一定时间内只想触发一次</p>
<p>防抖，持续触发只执行最后一次触发//写个固定表头就能用到了</p>
<h2 id="闭包"><a href="#闭包" class="headerlink" title="闭包"></a>闭包</h2><p>一个函数能访问另一个函数的作用域就是闭包<br>最简单的闭包就是function 里面再写一个function</p>
<p>闭包的缺点：</p>
<ul>
<li>内存泄漏</li>
</ul>
<p>闭包的优点: </p>
<ul>
<li>读取函数内部的变量</li>
<li>创建一个安全的环境，保证内部代码不受到外部的干涉，(实现私有成员，对外只暴露几个接口)</li>
</ul>
<h2 id="跨域问题"><a href="#跨域问题" class="headerlink" title="跨域问题"></a>跨域问题</h2><p>我觉得这个问题挺大的，另开一篇文来写吧<br>已经写了</p>
<ul>
<li>jsonp</li>
<li>iframe</li>
<li>cors</li>
<li>nginx<br><a href="%E8%A7%A3%E5%86%B3%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E6%B3%95.md">文章链接</a></li>
</ul>
<h2 id="原型链相关"><a href="#原型链相关" class="headerlink" title="原型链相关"></a>原型链相关</h2><p>MDN的解释</p>
<blockquote>
<p>JavaScript 只有一种结构：对象。每个实例对象（object）都有一个私有属性（称之为 __proto__ ）指向它的构造函数的原型对象（prototype）。该原型对象也有一个自己的原型对象（__proto__），层层向上直到一个对象的原型对象为 null。根据定义，null 没有原型，并作为这个原型链中的最后一个环节。</p>
</blockquote>
<p>__proto__像一个链接，指向对象的构造函数的prototype,函数才有prototype</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> Foo = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  <span class="keyword">var</span> s = <span class="number">10</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> foo = <span class="keyword">new</span> Foo();</span><br><span class="line"><span class="keyword">var</span> b = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  <span class="keyword">return</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(foo.__proto__);<span class="comment">//&#123;constructor: ƒ...&#125;</span></span><br><span class="line"><span class="built_in">console</span>.log(foo.prototype);<span class="comment">//undefined</span></span><br><span class="line"><span class="built_in">console</span>.log(Foo.prototype === foo.__proto__);<span class="comment">//true</span></span><br></pre></td></tr></table></figure>



<h2 id="事件委托"><a href="#事件委托" class="headerlink" title="事件委托"></a>事件委托</h2><p>一开始觉得这是个什么简单问题，在jquery里面直接用就好了</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">$(selector).on(event,childSelector,data,<span class="function"><span class="keyword">function</span>)</span></span><br><span class="line"><span class="function"></span></span><br></pre></td></tr></table></figure>
<p><img src="/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/jqueryOn.png" alt="描述"></p>
<p>看了别人的文章之后，发现自己其实只会用，并不清楚其中原理。<br>所以，事件委托到底是个什么东西呢？</p>
<p>其实就是委托父级代为执行事件，利用的是事件冒泡原理，元素的事件可以冒泡到父级，例如：要让ul里面的li点击事件，最原始的方法就是循环给所有的li增加点击事件，通过委托给ul，只需要在ul上添加一个点击事件即可。<br>委托的优势还有，对于新加入的li节点，点击也可以触发事件。</p>
<p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/liugang-vip/p/5616484.html">这边有一篇讲的很细致的参考博客</a><br>我感觉我这就是一篇博客收集文，😀</p>
<h2 id="输入url之后，到底发生了什么？"><a href="#输入url之后，到底发生了什么？" class="headerlink" title="输入url之后，到底发生了什么？"></a>输入url之后，到底发生了什么？</h2><p>这个问题，很眼熟吧，但是记不住，亏我之前还是网络专业的</p>
<ul>
<li><p>1.DNS解析</p>
</li>
<li><p>2.建立TCP连接<br><img src="/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/tcp.jpg" alt="三次握手 "></p>
<ul>
<li>第一次握手：客户端尝试连接服务器，向服务器发送 syn 包（同步序列编号Synchronize Sequence Numbers），syn=j，客户端进入 SYN_SEND 状态等待服务器确认</li>
<li>第二次握手：服务器接收客户端syn包并确认（ack=j+1），同时向客户端发送一个 SYN包（syn=k），即 SYN+ACK 包，此时服务器进入 SYN_RECV 状态</li>
<li>第三次握手：第三次握手：客户端收到服务器的SYN+ACK包，向服务器发送确认包ACK(ack=k+1），此包发送完毕，客户端和服务器进入ESTABLISHED状态，完成三次握手</li>
</ul>
</li>
<li><p>3.发送http请求</p>
</li>
<li><p>4.接收响应结果</p>
</li>
<li><p>5.解析html</p>
</li>
<li><p>6.渲染</p>
<p><img src="/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/url.png" alt="输入url之后，到底发生了什么"></p>
</li>
</ul>
<h2 id="http与https"><a href="#http与https" class="headerlink" title="http与https"></a>http与https</h2><p>二者区别：https安全性较高</p>
<blockquote>
<p>HTTP 与 HTTPS 区别<br>  HTTP 明文传输，数据都是未加密的，安全性较差，HTTPS（SSL+HTTP） 数据传输过程是加密的，安全性较好。<br>  使用 HTTPS 协议需要到 CA（Certificate Authority，数字证书认证机构） 申请证书，一般免费证书较少，因而需要一定费用。证书颁发机构如：Symantec、Comodo、GoDaddy 和 GlobalSign 等。<br>  HTTP 页面响应速度比 HTTPS 快，主要是因为 HTTP 使用 TCP 三次握手建立连接，客户端和服务器需要交换 3 个包，而 HTTPS除了 TCP 的三个包，还要加上 ssl 握手需要的 9 个包，所以一共是 12 个包。<br>  http 和 https 使用的是完全不同的连接方式，用的端口也不一样，前者是 80，后者是 443。<br>  HTTPS 其实就是建构在 SSL/TLS 之上的 HTTP 协议，所以，要比较 HTTPS 比 HTTP 要更耗费服务器资源。<br>  https = http + ssl<br>  https对传输数据进行加密处理</p>
</blockquote>
<p>HTTPS 的工作原理<br> <img src="https-intro.png" alt="HTTPS 的工作原理"></p>
<h2 id="重排与重绘"><a href="#重排与重绘" class="headerlink" title="重排与重绘"></a>重排与重绘</h2><p>能当那意思，但好像说不了很清晰</p>
<p>重排比重绘不好</p>
<p>对dom进行操作会导致重排<br>改变css之类的属性只会引起重绘</p>
<h2 id="ES6新特性"><a href="#ES6新特性" class="headerlink" title="ES6新特性"></a>ES6新特性</h2><p><a target="_blank" rel="noopener" href="https://es6.ruanyifeng.com/">阮一峰的博客</a></p>
<p>这里只讲几个常见容易记的</p>
<h3 id="const和let"><a href="#const和let" class="headerlink" title="const和let"></a>const和let</h3><ul>
<li>const:只读常量<br>  const对象之能使对象的地址不变，对象里面的值控制不了</li>
<li>let:局部变量<br>  1）只在当前代码块有效<br>  2）不会出现变量提升<br>  3）存在暂时性死区<br>  4）不允许重复声明</li>
</ul>
<h3 id="变量的解构赋值"><a href="#变量的解构赋值" class="headerlink" title="变量的解构赋值"></a>变量的解构赋值</h3><ul>
<li>形如 let [a,b] = [1,2]</li>
<li>解构赋值允许指定默认值<br>let[x,y=’2’] = [1]</li>
<li>应用:值的交换<br>let a =10,b=20;<br>[a,b] = [b,a]</li>
</ul>
<h3 id="模板字面量"><a href="#模板字面量" class="headerlink" title="模板字面量"></a>模板字面量</h3><p>这个其实没什么好说的，但我觉得对于我这种写过jquery的人来说，这东西太好了</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//原来的写法</span></span><br><span class="line"><span class="keyword">var</span> str = <span class="string">&quot;&lt;div&gt;&quot;</span></span><br><span class="line">        +<span class="string">&quot;&lt;span&gt;&quot;</span>+name+<span class="string">&quot;&lt;/span&gt;&quot;</span></span><br><span class="line">        +<span class="string">&quot;&lt;/div&gt;&quot;</span>;</span><br><span class="line"><span class="comment">//多好啊</span></span><br><span class="line"><span class="keyword">var</span> str1 = <span class="string">`&lt;div&gt;</span></span><br><span class="line"><span class="string">              &lt;span&gt;<span class="subst">$&#123;name&#125;</span>&lt;/span&gt;</span></span><br><span class="line"><span class="string">          &lt;/div&gt;`</span>;</span><br></pre></td></tr></table></figure>

<h3 id="展开运算符"><a href="#展开运算符" class="headerlink" title="展开运算符"></a>展开运算符</h3><p>三个点</p>
<ul>
<li>合并数组</li>
<li>替代apply</li>
<li>解构赋值</li>
<li>字符串转数组</li>
<li>具有 Iterator 接口的对象,转换成数组</li>
<li>浅拷贝<br><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/3935a80342a0">ES6之展开运算符(…)</a></li>
</ul>
<h3 id="剩余参数-可变参数"><a href="#剩余参数-可变参数" class="headerlink" title="剩余参数(可变参数)"></a>剩余参数(可变参数)</h3><p>也是三个点<br>用于剩余的将不定数量的参数收集成数组<br>我觉得上面展开运算符的解构赋值就是剩余参数</p>
<h3 id="ES6箭头函数"><a href="#ES6箭头函数" class="headerlink" title="ES6箭头函数"></a>ES6箭头函数</h3><ul>
<li>this 指向不能改变</li>
<li>this指向箭头函数创建词法作用域的this</li>
</ul>
<h3 id="默认参数函数"><a href="#默认参数函数" class="headerlink" title="默认参数函数"></a>默认参数函数</h3><ul>
<li>function test(a=2,b)</li>
</ul>
<h3 id="默认值与解构"><a href="#默认值与解构" class="headerlink" title="默认值与解构"></a>默认值与解构</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> foo = <span class="function"><span class="keyword">function</span>(<span class="params">&#123;x=<span class="number">2</span>,y&#125;</span>)</span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(x,y)</span><br><span class="line">&#125;</span><br><span class="line">foo(&#123;<span class="attr">y</span>:<span class="number">10</span>&#125;)</span><br></pre></td></tr></table></figure>
<h3 id="Promise"><a href="#Promise" class="headerlink" title="Promise"></a>Promise</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第四题：手动实现Promise</span></span><br><span class="line">   <span class="class"><span class="keyword">class</span> <span class="title">myPromise</span></span>&#123;</span><br><span class="line">     <span class="title">constructor</span> (<span class="params">handle</span>)&#123;</span><br><span class="line">       <span class="function"><span class="title">if</span>(<span class="params"><span class="keyword">typeof</span> handle !== <span class="string">&quot;function&quot;</span></span>)</span>&#123;</span><br><span class="line">           <span class="keyword">throw</span> <span class="keyword">new</span> <span class="built_in">TypeError</span>(<span class="string">&#x27;Promise resolver $&#123;executor&#125; is not a function&#x27;</span>)</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="comment">//记录状态和值的改变</span></span><br><span class="line">       <span class="comment">//初始化值</span></span><br><span class="line">       <span class="built_in">this</span>.value = <span class="literal">null</span> <span class="comment">//终值</span></span><br><span class="line">       <span class="built_in">this</span>.reason = <span class="literal">null</span> <span class="comment">//拒因</span></span><br><span class="line">       <span class="built_in">this</span>.state = <span class="string">&#x27;pending&#x27;</span> <span class="comment">//状态</span></span><br><span class="line">       <span class="keyword">const</span> resolve = <span class="function"><span class="params">value</span> =&gt;</span>&#123;</span><br><span class="line">         <span class="comment">//成功后的一系列操作（状态的改变，成功回调的执行）</span></span><br><span class="line">         <span class="function"><span class="title">if</span>(<span class="params"><span class="built_in">this</span>.state === <span class="string">&#x27;pending&#x27;</span></span>)</span>&#123;</span><br><span class="line">           <span class="comment">//状态进行改变</span></span><br><span class="line">           <span class="built_in">this</span>.state = <span class="string">&#x27;fulfilled&#x27;</span></span><br><span class="line">           <span class="comment">//执行成功的回调，把终值进行赋值</span></span><br><span class="line">           <span class="built_in">this</span>.value = value</span><br><span class="line">         &#125;</span><br><span class="line">       &#125;</span><br><span class="line">       <span class="keyword">const</span> reject = <span class="function"><span class="params">reason</span> =&gt;</span>&#123;</span><br><span class="line">           <span class="comment">//失败后的一系列操作（状态的改变，失败回调的执行）</span></span><br><span class="line">           <span class="function"><span class="title">if</span>(<span class="params"><span class="built_in">this</span>.state === <span class="string">&#x27;pending&#x27;</span></span>)</span>&#123;</span><br><span class="line">               <span class="comment">//状态进行改变</span></span><br><span class="line">               <span class="built_in">this</span>.state = <span class="string">&#x27;rejected&#x27;</span></span><br><span class="line">               <span class="comment">//执行成功的回调，把据因进行赋值</span></span><br><span class="line">               <span class="built_in">this</span>.reason = reason</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;</span><br><span class="line">       executor(resolve,reject)</span><br><span class="line">     &#125;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

<h3 id="for…of循环"><a href="#for…of循环" class="headerlink" title="for…of循环"></a>for…of循环</h3><p>可迭代类型的数据都可以使用for of循环，不需要通过下标来取值</p>
<h3 id="类与继承"><a href="#类与继承" class="headerlink" title="类与继承"></a>类与继承</h3><p>这一块比较复杂，再开一篇</p>
</div><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">憨憨一个</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://blog.better2020.top/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/">http://blog.better2020.top/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://blog.better2020.top" target="_blank">Han's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/JS/">JS</a></div><div class="post_share"><div class="social-share" data-image="/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BJS/top_img.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/08/31/%E4%BD%BF%E7%94%A8markdown%E5%86%99%E7%AE%80%E5%8E%86%E5%B9%B6%E8%BD%AC%E6%88%90pdf/"><img class="prev-cover" src="/2021/08/31/%E4%BD%BF%E7%94%A8markdown%E5%86%99%E7%AE%80%E5%8E%86%E5%B9%B6%E8%BD%AC%E6%88%90pdf/top_img.png" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">markdown写简历并转成pdf</div></div></a></div><div class="next-post pull-right"><a href="/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BCSS/"><img class="next-cover" src="/2021/08/27/%E9%9D%A2%E8%AF%95%E9%A2%98%E4%B9%8BCSS/top_img.png" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">面试题之CSS</div></div></a></div></nav></article></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 憨憨一个</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><section id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></section><div class="search-dialog" id="local-search"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script>(function(){
  const bp = document.createElement('script');
  const curProtocol = window.location.protocol.split(':')[0];
  if (curProtocol === 'https'){
  bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
  }
  else{
  bp.src = 'http://push.zhanzhang.baidu.com/push.js';
  }
  bp.dataset.pjax = ''
  const s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(bp, s);
})()</script></div></body></html>